/*
 * @lc app=leetcode.cn id=636 lang=javascript
 *
 * [636] 函数的独占时间
 */

// @lc code=start
/**
 * @param {number} n
 * @param {string[]} logs
 * @return {number[]}
 */
var exclusiveTime = function(n, logs) {
   let res = new Array(n).fill(0);
   let i = 0;
   function getNext() {
       let dure = 0;
       const starts = logs[i].split(':');
       while(i < logs.length -1 && logs[++i].indexOf('s') !== -1) {
         dure = dure + getNext();
       }
       const ends = logs[i].split(':');
       const totalDure = Number(ends[2]) - Number(starts[2]) + 1;
       res[Number(starts[0])] += (totalDure - dure);
       return totalDure;
   }
   while(i < logs.length) {
       getNext();
       i++;
   }
   return res;
};
// @lc code=end

